package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import java.util.Date;

public class DAYSOFYEAR extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    int i;
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    Object localObject = paramArrayOfObject[0];
    if (localObject instanceof Date)
      i = ((Date)localObject).getYear();
    else if (localObject instanceof Number)
      i = ((Number)localObject).intValue();
    else
      return Primitive.ERROR_NAME;
    if ((i % 400 == 0) || ((i % 4 == 0) && (i % 100 != 0)))
      return new Integer(366);
    return new Integer(365);
  }

  public Function.Type getType()
  {
    return Function.DATETIME;
  }

  public String getCN()
  {
    return "DAYSOFYEAR(year):返回某年包含的天数。\n示例：\nDAYSOFYEAR(2008)等于365，等价于DAYSOFYEAR(\"2008-01-01\")。";
  }

  public String getEN()
  {
    return "";
  }
}